<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Carbon;

/**
 * @property int $id
 * @property int $category_id
 * @property string $cover
 * @property string $title
 * @property string $keywords
 * @property string $description
 * @property string $content
 * @property string $markdown
 * @property bool $is_top
 * @property bool $is_recommend
 * @property int $status
 * @property int $sort
 * @property int $push_status
 * @property Carbon|null $push_time
 * @property Carbon|null $published_at
 * @property string $author
 * @property int $views
 * @property string $source
 * @property Carbon $created_at
 * @property Carbon $updated_at
 * @property ArticleCategory $category
 * @property ArticleTag[] $tags
 */
class Article extends Model
{
    protected $guarded = [];

    public function category(): BelongsTo
    {
        return $this->belongsTo(ArticleCategory::class, 'category_id', 'id');
    }

    public function tags(): BelongsToMany
    {
        return $this->belongsToMany(ArticleTag::class, 'article_has_tags', 'article_id', 'article_tag_id');
    }

    public function views(): HasMany
    {
        return $this->hasMany(ArticleView::class, 'article_id', 'id');
    }
}
